<template>
  <div class="mobile-container">
    <div class="app-content">
      <!-- 顶部栏 -->
      <div class="header">
        <div class="header-top">
          <div class="back-icon" @click="handleBack">
            <Icon icon="mdi:arrow-left"/>
          </div>
          <div class="page-title">WP兑换二维码</div>
          <div class="scan-icon" @click="handleScan">
            <Icon icon="mdi:line-scan"/>
          </div>
        </div>
      </div>

      <!-- 二维码展示区域 -->
      <div class="qrcode-section">
        <div class="qrcode-card">
          <div class="user-info">
            <div class="user-phone">{{ userInfo.phone }}</div>
            <div class="cardpack-text">的卡包码</div>
          </div>
          <div class="qrcode-container">
            <div class="qrcode-wrapper">
              <img :src="qrcodeImage" alt="WP兑换二维码" class="qrcode-img" />
              <!-- 二维码刷新动画 -->
              <div class="qrcode-refresh" v-if="isRefreshing">
                <Icon icon="mdi:refresh" class="refresh-icon" />
              </div>
            </div>
          </div>

          <!-- 保存按钮 -->
          <button class="save-btn" @click="handleSaveCardpack">
            <Icon icon="mdi:download" class="save-icon" />
            保存卡包码
          </button>
        </div>
      </div>

      <!-- 小账本入口 -->
      <div class="ledger-section" @click="handleLedger">
        <div class="ledger-item">
          <div class="ledger-left">
            <Icon icon="mdi:notebook-outline" class="ledger-icon" />
            <div class="ledger-text">小账本</div>
          </div>
          <Icon icon="mdi:chevron-right" class="ledger-arrow" />
        </div>
      </div>

      <!-- 使用说明 -->
      <div class="instruction-section">
        <div class="instruction-title">使用说明</div>
        <div class="instruction-list">
          <div class="instruction-item">
            <div class="item-number">1</div>
            <div class="item-text">出示此二维码供用户扫描兑换</div>
          </div>
          <div class="instruction-item">
            <div class="item-number">2</div>
            <div class="item-text">用户扫描后即可完成WP兑换</div>
          </div>
          <div class="instruction-item">
            <div class="item-number">3</div>
            <div class="item-text">可在小账本中查看交易记录</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { Icon } from '@iconify/vue2'

export default {
  name: 'MerchantCodePage',
  components: {
    Icon
  },
  data() {
    return {
      isRefreshing: false,
      userInfo: {
        phone: '191****2669'
      },
      qrcodeImage: require('../../../assets/images/wp_qr_code.png')
    }
  },
  mounted() {
  },
  methods: {
    handleBack() {
      this.$router.go(-1)
    },

    handleScan() {
      // TODO: 实现扫码功能
      alert('调用扫码功能')
    },

    handleSaveCardpack() {
      // TODO: 实现保存卡包码功能
      this.isRefreshing = true

      // 模拟保存过程
      setTimeout(() => {
        this.isRefreshing = false
        alert('卡包码已保存到相册')
      }, 1000)
    },

    handleLedger() {
       this.$router.push('/userdistribution/merchantwpad')
    }
  }
}
</script>

<style scoped>
.mobile-container {
  width: 100%;
  min-height: 100vh;
  background: #f5f5f5;
  display: flex;
  justify-content: flex-start;
  align-items: flex-start;
  padding: 20px;
}

.app-content {
  width: 375px;
  min-height: 667px;
  background: white;
  border-radius: 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}

/* 顶部栏样式 */
.header {
  padding: 15px 20px;
  background: white;
  border-bottom: 1px solid #f0f0f0;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.back-icon {
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: #333;
}

.page-title {
  font-size: 18px;
  font-weight: 600;
  color: #333;
}

.scan-icon {
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: #333;
}

/* 二维码展示区域 */
.qrcode-section {
  padding: 40px 20px 30px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.qrcode-card {
  background: white;
  border-radius: 20px;
  padding: 30px 20px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

.qrcode-container {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

.qrcode-wrapper {
  position: relative;
  width: 200px;
  height: 200px;
  background: white;
  border-radius: 12px;
  padding: 10px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.qrcode-img {
  width: 100%;
  height: 100%;
  border-radius: 8px;
  object-fit: cover;
}

.qrcode-refresh {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  animation: spin 1s linear infinite;
}

.refresh-icon {
  font-size: 32px;
  color: #667eea;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.user-info {
  margin-bottom: 25px;
}

.user-phone {
  font-size: 16px;
  font-weight: 600;
  color: #333;
  margin-bottom: 4px;
}

.cardpack-text {
  font-size: 14px;
  color: #666;
}

.save-btn {
  width: 100%;
  max-width: 200px;
  height: 44px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 22px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
  margin: 0 auto;
}

.save-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.save-btn:active {
  transform: translateY(0);
}

.save-icon {
  font-size: 18px;
}

/* 小账本入口 */
.ledger-section {
  padding: 0 20px;
  margin: 20px 0;
}

.ledger-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  background: white;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
  border: 1px solid #f0f0f0;
}

.ledger-item:hover {
  background: #f8f9fa;
  transform: translateX(4px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.ledger-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ledger-icon {
  font-size: 20px;
  color: #667eea;
}

.ledger-text {
  font-size: 16px;
  font-weight: 500;
  color: #333;
}

.ledger-arrow {
  color: #999;
  font-size: 18px;
}

/* 使用说明区域 */
.instruction-section {
  padding: 0 20px;
  margin-top: 20px;
}

.instruction-title {
  font-size: 16px;
  font-weight: 600;
  color: #333;
  margin-bottom: 16px;
  padding-left: 8px;
}

.instruction-list {
  background: white;
  border-radius: 12px;
  padding: 20px;
  border: 1px solid #f0f0f0;
}

.instruction-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 16px;
}

.instruction-item:last-child {
  margin-bottom: 0;
}

.item-number {
  width: 24px;
  height: 24px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}

.item-text {
  font-size: 14px;
  color: #666;
  line-height: 1.5;
  padding-top: 2px;
}

/* 响应式设计 */
@media (max-width: 375px) {
  .mobile-container {
    padding: 0;
  }

  .app-content {
    width: 100%;
    min-height: 100vh;
    border-radius: 0;
  }

  .qrcode-wrapper {
    width: 180px;
    height: 180px;
  }
}
</style>
